<?php
require("res/const.php");
require_once("lib/auth/session.php");
require_once("lib/auth/user.php");
require_once("lib/sqlConnector.php");
// Gets post from DB
function getPost($postid) {
    sqlQuery("UPDATE posts SET views=(views+1) WHERE postid= '%s'",$postid);
    $result = sqlQuery("SELECT * FROM posts WHERE postid = '%s'",$postid);
    $temp = mysql_fetch_assoc($result);
    $temp['name'] = id2Name($temp['userid']);
    return $temp;
}

// Gets the latest # posts
function getLatest($amount) {
    return translateMultirow(sqlQuery("SELECT * FROM posts ORDER BY date DESC LIMIT %s",$amount));
}

function getNewerThan($id) {
    $tmp = mysql_fetch_row(sqlQuery("SELECT date FROM posts WHERE postid='%s'",$id));
    $date = $tmp[0];
    return translateMultirow(sqlQuery("SELECT * FROM posts WHERE date > '%s' ORDER BY date ASC",$date));
}

function translateMultirow($resource) {
    $arr = Array();
    while($temp = mysql_fetch_assoc($resource)) {
    	//$temp['img'] = $IMAGE_PATH . "image_" . $temp['postid'] . ".gif";
    	$temp['name'] = id2Name($temp['userid']);//problem is here
        $arr[] = $temp;
    }
    return $arr;
}

?>